package com.ruoyi.deeplearn.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.deeplearn.domain.DeepModelDataset;
import com.ruoyi.deeplearn.service.IDeepModelDatasetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模型Controller
 *
 * @author rww
 * @date 2022-12-22
 */
@RestController
@RequestMapping("/deeplearn/modelDataset")
public class DeepModelDatasetController extends BaseController
{
    @Autowired
    private IDeepModelDatasetService deepModelDatasetService;

    /**
     * 查询模型列表
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:modelDataset:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeepModelDataset deepModelDataset)
    {
        startPage();
        List<DeepModelDataset> list = deepModelDatasetService.selectDeepModelDatasetList(deepModelDataset);
        return getDataTable(list);
    }

    /**
     * 导出模型列表
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:modelDataset:export')")
    @Log(title = "模型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeepModelDataset deepModelDataset)
    {
        List<DeepModelDataset> list = deepModelDatasetService.selectDeepModelDatasetList(deepModelDataset);
        ExcelUtil<DeepModelDataset> util = new ExcelUtil<DeepModelDataset>(DeepModelDataset.class);
        util.exportExcel(response, list, "模型数据");
    }

    /**
     * 获取模型详细信息
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:modelDataset:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deepModelDatasetService.selectDeepModelDatasetById(id));
    }

    /**
     * 新增模型
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:modelDataset:add')")
    @Log(title = "模型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeepModelDataset deepModelDataset)
    {
        return toAjax(deepModelDatasetService.insertDeepModelDataset(deepModelDataset));
    }

    /**
     * 修改模型
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:modelDataset:edit')")
    @Log(title = "模型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeepModelDataset deepModelDataset)
    {
        return toAjax(deepModelDatasetService.updateDeepModelDataset(deepModelDataset));
    }

    /**
     * 删除模型
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:modelDataset:remove')")
    @Log(title = "模型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deepModelDatasetService.deleteDeepModelDatasetByIds(ids));
    }
}
